<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>我的关注</title>
<script type="text/javascript" src="Public/js/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="Public/bootstrap/js/bootstrap.min.js"></script>
<script type="text/javascript" src="Public/js/lazyload.js"></script>
<script type="text/javascript" src="Public/artDialog/artDialog.source.js?skin=default" charset="utf-8"></script>
<script type="text/javascript" src="Public/js/jquery.ae.image.resize.min.js"></script>
<script type="text/javascript" src="Public/js/province_city_county.js"></script>

<link rel="stylesheet" href="Public/bootstrap/css/bootstrap.css">
<link rel="stylesheet" href="theme/default/css/common.css">
<link rel="stylesheet" href="Public/css/homeindex.css">

  <!--[if lte IE 6]>
  <link rel="stylesheet" type="text/css" href="Public/bootstrap/css/bootstrap-ie6.css">
  <![endif]-->
  <!--[if lte IE 7]>
  <link rel="stylesheet" type="text/css" href="Public/bootstrap/css/ie.css">
  <![endif]-->
</head>

<body>
<include file="./template/default/Public/header-logined.html" />


    <div class="container main">
      <div class="row-fluid">
        <div class="span3">
          <include file="./template/default/Public/sidebar.html" />
        </div><!--/span-->
        <div class="content span9">

        
          <div class="well">
          	<div class="page-header"><h3>我的关注</h3></div>
<script type="text/javascript">
function SetFocus(baby_id,vid){
	var baby_flag=$('#baby_flag_'+baby_id).val();
	var flag='';
	if(baby_flag==0){
		//关注
		flag = 1;
	}else{
		//未关注
		flag = 0;
	}
	$.ajax({
	url:'/index.php',
	type:'GET',
	data:'s=/Home/Baby/setFoucs/baby_id/'+baby_id+'/vid/'+vid+'/flag/'+flag+'/tp/'+new Date().getTime(),
	dataType:'json',
	success:function(json){
		
		$('#baby_flag_'+baby_id).attr("value",flag);
		
		if(flag==1){
		$('#focus_btn_'+baby_id).addClass('btn-success');
		getFocusList();
		}else{
			$('#focus_btn_'+baby_id).removeClass('btn-success');
			getFocusList();
			//$('#baby_'+baby_id+'').remove();
		}
	}
	});
}

function GetInvite(){
	var invite_code = $.trim($('#invite_code').val());
	$('#invite_flag').html('');
	if(invite_code!=''){
		//邀请码不为空
		$('#invite_flag').html('<img src="Public/images/spinner.gif" align="absmiddle" width="24" height="24"> 数据查询中...');
		$.ajax({
			url:"/index.php",
			type:"GET",
			data:"s=/Home/Baby/queryFocus/invite_code/"+invite_code+"/tp/"+new Date().getTime(),
			dataType:"json",
			success:function(json){
				var html = '';
				$('#invite_flag').html('');
				if(json.length>0){
				//有数据
					$('#invite_flag').html('邀请码有效!');
					//进行数据显示
					$.each(json,function(dataIndex,data){
						html+='<li><div><div class="thumbnail"><img src="'+data.baby_icon+'" width="64" height="64" style="visibility:visible;"></div><div class="caption"><h4>'+data.baby_realname+'</h4><p><input type="hidden" id="baby_flag_'+data.baby_id+'" value="0"><button class="btn btn-mini" onclick="SetFocus('+data.baby_id+','+data.v_id+')" id="focus_btn_'+data.baby_id+'">我要关注</button></p></div></div></li>';
					});
					
					$('#baby_thumb').html(html);
				}else{
				//无数据
				$('#invite_flag').html('邀请码不正确或已经被使用!');
				}
			}
				
		});
	}else{
		$('#invite_code').focus();
		$('#invite_flag').html('邀请码不能为空!');
	}
}
</script>            
<form class="form-inline" onSubmit="return false;">            
<label>输入邀请码 </label>
&nbsp;
<input type="text" name="invite_code" id="invite_code"> 
&nbsp;
<button type="button" class="btn" onClick="GetInvite()">查看详情</button>
&nbsp;
<span id="invite_flag"></span>
</form>

<div>
<h2>邀请码</h2>
<table>
<tbody>
<tr>
	<td></td>
    <td></td>
    <td></td>
</tr>
</tbody>
</table>
</div>

<div>
<ul class="thumbnails" id="baby_thumb">
</ul>
</div>

<div class="row" style="margin:0 auto">
<table class="table table-striped">
<thead>
	<tr>
    	<th>序</th>
        <th>邀请码</th>
        <th>邀请时间</th>
        <th>使用状态</th>
    </tr>
</thead>
<tbody>
<volist name="result_code" id="rs_code" key="k" >
	<tr>
    	<td>{$k}</td>
        <td>{$rs_code['v_code']}</td>
        <td><?php echo date("Y-m-d H:i:s",$rs_code['v_createdate']);?></td>
        <td>{$rs_code['v_flag']}</td>
    </tr>
</volist>    
</tbody>
</table>
</div>

<script type="text/javascript">
function btnHover(){
$(".followBtn").hover(function(){
		$(this).removeClass("btn-success");
		$(this).addClass("btn-danger");
		$(this).html('取消关注');
	},function(){
		$(this).removeClass("btn-danger");
		$(this).addClass("btn-success");
		$(this).html('正在关注');
});	
}

function unFocus(babyid){
	if(confirm('你是否取消取该宝宝的关注?')){
		$.ajax({
			url:'/index.php?s=/Home/Baby/unFocus/babyid/'+babyid+'',
			type:'GET',
			dataType:'json',
			success:function(data){
				if(data['focus']=="yes"){
					//$('#focus_stat').html('<a href="javascript:void(0)" class="btn profileFollowBtn btn-warning">取消成功</a>');
					$('#baby_'+babyid+'').remove();
				}else if(data['focus']=="no"){
					
				}
			}
		});
	}
}
function getFocusList(){
	$.ajax({
	url:'/index.php?s=/Home/Baby/FocusList/',
	type:'GET',
	dataType:'JSON',
	success:function(json){
		var thumb = '';
		if(json.length>0){
			$.each(json,function(dataIndex,data){
				
				thumb+='<li class="span4" id="baby_'+data.baby_id+'">                <div class="thumbnail">                  <div style="background:#ccc;width:98%;height:158px;overflow:hidden;margin:0 auto;"><img src="'+data.baby_icon+'"></div>                 <div lass="caption">                    <h3>'+data.baby_realname+'</h3>                    <p></p>                    <p align="text-align:center">                   <span id="focus_stat">                    <a onclick="unFocus(\''+data.baby_id+'\')" class="followBtn btn profileFollowBtn btn-success btn-mini" href="javascript:void(0)">正在关注</a>                    </span>                                       <span id="upload_btn">                    <a href="/index.php?s=/Home/Albums/myFocusQiniupload/babyid/'+data.baby_id+'" class="btn rofileFollowBtn btn-info btn-mini" target="_blank">上传相片</a>                    	                    </span>                   	<span id="focus_view">                   <a href="/index.php?s=/Home/Baby/myFocus/babyid/'+data.baby_id+'" class="btn profileFollowBtn btn-info btn-mini" target="_blank">查看</a>                   </span>                    </p>                  </div>                </div></li>';
			});
		}else{
			thumb='<li>暂时还没有关注!</li>';	
		}

		$('#thumbnails').html(thumb);
		btnHover();
	}
	});	
}
</script>

<div class="tab-content" style="background:#fff;">
<ul class="thumbnails" id="thumbnails">
      
              
              
            </ul>
</div>

            
            
          </div><!--end well-->
         
        </div><!--/span-->
      </div><!--/row-->
      
      </div>
      
<script type="text/javascript">
$(document).ready(function(){
getFocusList();	
});
</script>      
      
<include file="./template/default/Public/footer-logined.html" />
    
</body>
</html>